package com.lframework.xingyun.basedata.controller;

import com.lframework.starter.web.core.annotations.security.HasPermission;
import com.lframework.starter.web.core.controller.DefaultBaseController;
import com.lframework.starter.web.core.components.resp.InvokeResult;
import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
import com.lframework.xingyun.basedata.bo.member.QueryMemberAccountBo;
import com.lframework.xingyun.basedata.service.member.MemberAccountService;
import com.lframework.xingyun.basedata.vo.member.MemberAccountChangeVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * 会员积分账户 Controller
 *
 * @author mos
 */
@Api(tags = "会员积分账户")
@Validated
@RestController
@RequestMapping("/basedata/member-account")
public class MemberAccountController extends DefaultBaseController {

    @Autowired
    private MemberAccountService memberAccountService;

    /**
     * 查询会员积分账户
     */
    @ApiOperation("查询会员积分账户")
    @ApiImplicitParam(value = "memberId", name = "memberId", paramType = "query", required = true)
    @HasPermission({"base-data:member-account:query"})
    @GetMapping
    public InvokeResult<QueryMemberAccountBo> getByMemberId(@NotBlank(message = "ID不能为空！") String memberId) {
        return InvokeResultBuilder.success(memberAccountService.queryByMemberId(memberId));
    }

    /**
     * 积分变动
     */
    @ApiOperation("积分变动")
    @HasPermission({"base-data:member-account:change"})
    @PostMapping("/change")
    public InvokeResult<String> changeScore(@RequestBody @Validated MemberAccountChangeVo vo) {
        return InvokeResultBuilder.success(memberAccountService.changeScore(vo));
    }
}

